package com.example.helloworld;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.TextView;

import com.example.helloworld.widget.DateTimePicker.OnDateTimeChangedListener;

public class DateTimePicker extends Activity {
	final SimpleDateFormat dateFormat =	new SimpleDateFormat("yyyy-MM-dd HH:mm");
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_date_time_picker);
		
		final TextView text =	(TextView)findViewById(R.id.currentDateTimeText);
		final com.example.helloworld.widget.DateTimePicker picker =
								(com.example.helloworld.widget.DateTimePicker)findViewById(R.id.dateTimePicker);
		
		picker.setOnDateTimeChangedListner(new OnDateTimeChangedListener() {

			@Override
			public void onDateTimeChanged(
					com.example.helloworld.widget.DateTimePicker view,
					int year, int monthOfYear, int dayOfYear, int hourOfDay,
					int minute) {
				Calendar calendar =	Calendar.getInstance();
				calendar.set(year, monthOfYear, dayOfYear, hourOfDay, minute);
				
				text.setText(dateFormat.format(calendar.getTime()));
			}
			
		});

		Calendar calendar =	Calendar.getInstance();
		calendar.set(picker.getYear(), picker.getMonth(), picker.getDayOfMonth(), picker.getCurrentHour(), picker.getCurrentMinute());
		text.setText(dateFormat.format(calendar.getTime()));
	}
}
